﻿Imports Equipment.DataAccess
Imports Equipment.Business

Public Class RequirementWrapper
    Inherits Requirement

#Region "Properties"

    Public ReadOnly Property FrequencyDescription As String
        Get
            Return Requirement.GetFrequencyDescriptionByType(Me.FrequencyType)
        End Get
    End Property

    Public ReadOnly Property MeasureDescriptions As String
        Get
            Return String.Join(", ", Me.Measures.Select(Function(m) m.MeasureDescription))
        End Get
    End Property


    Public ReadOnly Property CreatedByUserFullName As String
        Get
            Return If(Me.CreatedByUser IsNot Nothing, Me.CreatedByUser.FullName, String.Empty)
        End Get
    End Property

    Public ReadOnly Property AssetTypeDescription As String
        Get
            Return Me.AssetType.Description
        End Get
    End Property

    Public ReadOnly Property RequirementTypeDescription As String
        Get
            Return RequirementTypeLookup.GetDescriptionByType(Me.Type)
        End Get
    End Property

    Public ReadOnly Property FormatedCreatedDate As String
        Get
            Return Me.CreatedDate.ToString("dd/MM/yy hh:mm tt")
        End Get
    End Property



#End Region

    Public Shared Function ConvertToWrapperList(ByVal source As IEnumerable(Of Equipment.DataAccess.Requirement)) As List(Of RequirementWrapper)
        Dim wrapperList As New List(Of RequirementWrapper)

        For Each r In source
            Dim w As New RequirementWrapper
            w.AssetType = r.AssetType
            w.FrequencyType = r.FrequencyType
            w.ID = r.ID
            w.Name = r.Name
            w.Type = r.Type
            w.Measures = r.Measures
            w.CreatedDate = r.CreatedDate
            w.CreatedByUser = r.CreatedByUser

            wrapperList.Add(w)
        Next

        Return wrapperList
    End Function
End Class
